import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;


public class implementation {

	private static int y;
    static int k=0;

	public static void main(String args[]) throws IOException, ParseException, SQLException{

		Connection con=null;
		String url="jdbc:mysql://localhost:3306/";
		String db="cpmerge";
		String driver="com.mysql.jdbc.Driver";
		
		
		
		Scanner in = new Scanner(System.in);
		String input =in.nextLine();
		int len=input.length() + 2;
				
		if(len>26)
			y=26;
		else
			y=len;
		System.out.println(y);
		double t=0.7*y;
		System.out.println(t);
		int tau=(int) Math.floor(t);
		System.out.println(tau);
		
		String temp=input.concat("$$");
	    String Token="$$".concat(temp);//add $$ before and after word
	    int length=Token.length();
	    
	    String trigram[] = new String[length-2];
	    char []c = Token.toCharArray();//each word to character array
	    
	    for(int i=0;i<(length-2);i++)
	    {//create trigrams
	    	char []cn={c[i],c[i+1],c[i+2]};
	    	trigram[i] = new String(cn);
	    	
	    }
	    
	    HashMap<Integer, Integer> hm=new HashMap<Integer, Integer>();
	    HashMap<Integer, Integer> hr=new HashMap<Integer, Integer>();
	   
	    int found[] = null;

		for(int i=0;i<=(len-tau);i++){
			
			k=0;
			found=indexSearch(trigram[i]);
			
			for(int j=0;j<found.length;j++){
				
				if(hm.containsKey(found[j])){
					k=(int) hm.get(found[j]);
					k++;
					hm.put(found[j], k);
				}
				else
					{k=1;
				
				hm.put(found[j], k);
					}
				System.out.println(k);
				
				
				}
			}
		
	    

		for(int i=(len-tau+1);i<len;i++){

						
int count=0;
				for (Iterator<Integer> itr = hm.keySet().iterator(); itr.hasNext(); )  {
					count++;

			
			    	int next=itr.next();

				FileReader fr=new FileReader("J:\\Anita TIFR\\Demo\\demotrigrams\\"+next+".txt");//reading from dictionary
				BufferedReader fbr=new BufferedReader(fr);
				String str=fbr.readLine();
				while(str!=null){
					
					
					if(str.equals(trigram[i])){
						
						k=hm.get(next);
						k++;
						
						System.out.println(str + " = "+trigram[i] +" = " +k+" = "+next);
						hm.put(next, k);
						
					}
					

					str=fbr.readLine();
				}
				int val=hm.get(next);
				
				if(val>=tau){
					hr.put(next,val);
					itr.remove();  

					}
				else if((val+(len-count+1))<tau){
					
					itr.remove();
					
				}
				
				
				}
				
				
			
		}
			
			Iterator<Integer> it = hr.keySet().iterator();
			
			try{
				Class.forName(driver);
				con=DriverManager.getConnection(url+db, "root", "");
			}
			catch(Exception e){
				e.printStackTrace();
			}
			Statement st=con.createStatement();
			
			while (it.hasNext())
			   {
			      int last = it.next();
			      			      
			    	  String sql="SELECT names FROM bioset WHERE number = "+last;
				      
				      st=con.createStatement();
				      ResultSet rs=st.executeQuery(sql);
				      while (rs.next()) {
				            String name =
				                rs.getString("names");
				            System.out.println(name);
				      }
			      
			   }
		

	}
	
	
	
	public static int[] indexSearch(String input) throws IOException, ParseException{
		

	    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);

	    FSDirectory index = FSDirectory.open(new File("J:\\Anita TIFR\\Demo\\demoindex"));

	    
	    Query q = new QueryParser(Version.LUCENE_34, "content", analyzer).parse(input);

	    int hitsPerPage = 50;
	    IndexReader indexReader = IndexReader.open(index);
	    IndexSearcher searcher = new IndexSearcher(indexReader);

	    TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
	    searcher.search(q, collector);
	    ScoreDoc[] hits = collector.topDocs().scoreDocs;
	   
	    // 4. display results
	    System.out.println("Found " + hits.length + " hits.");
	    int []j=new int[hits.length];
	    for(int i=0;i<hits.length;++i) {
	        int docId = hits[i].doc;
	        Document d = searcher.doc(docId);
	        String str=d.get("filename");
	        int ind=str.indexOf(".");
	        
	        j[i] =Integer.parseInt(str.substring(0, ind));
	        
	    }
		return j;
		
	}
	  
	
	
}
